<?php
// 本类由系统自动生成，仅供测试用途
class UserAction extends Action {
    public function index(){
        header("Content-Type:text/html; charset=utf-8");
		$this->display();
        
    }
	public function add(){
      
		$Data = $_REQUEST["Data"];
		$Dao=D("User");
		$Data['password']=MD5($Data['password']);
		$Data['regdate']=date('Y-m-d');
		$Data['depart']="待审批";
		if($Dao->add($Data))		
			print_r("success!");
		else
			print_r("error!");
        
    }
	public function update(){
      
		$Data = $_REQUEST["Data"];
		$Dao=D("User");
		$Data["uid"]=session('uid');
		$Data['password']=MD5($Data['password']);
		
		if($Dao->save($Data))		
			print_r($Data['depart']);
		else
			print_r("error!");
        
    }
	public function loaduserinfo(){
      
		//$condition['uid']=$_REQUEST["uid"];
		$condition['uid']=session ( 'uid' );
		$Dao=D("User");
		$User=$Dao->where($condition)->find();
		$User["password"]="";
		$Data=json_encode($User);
		print_r($Data);
		
        
    }
	public function query(){
		$key=$_REQUEST["key"];
		$pageIndex = $_REQUEST["pageIndex"];
		$pageSize = $_REQUEST["pageSize"];
	
		$sortField = $_REQUEST["sortField"];
		$sortOrder = $_REQUEST["sortOrder"];
		
		if(!empty($sortField)){
			if ($sortOrder != "desc") $sortOrder = "asc";
			$order = $sortField . " " . $sortOrder;
		}else{
			$order = "uid desc";
		}
		
		$condition ['nickname'] = array ('like', '%' . $key . '%' );
		
		$Dao=D("User");
		
		$total = $Dao->where ( $condition )->count ();
		
		//dump($total);
		$list=$Dao->where($condition)->order ( $order )->limit ( $pageIndex * $pageSize. ',' . $pageSize )->select();
		
		//dump($list);
		$resultData = array("total"=>$total,"data"=>$list);

		$Data=json_encode($resultData);
		print_r($Data);
		
        
    }
		
}